package com.wan.data.resource.converter;

import cn.hutool.core.convert.Converter;
import cn.hutool.core.convert.ConverterRegistry;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * @author wwh
 * @date 2022/7/5 14:51
 */
public class ConverterManager {

    private static final ConverterRegistry converterRegistry;

    static {
        converterRegistry = new ConverterRegistry();
        converterRegistry.putCustom(int[].class,new IntArrayConverter());
        converterRegistry.putCustom(JSONArray.class,new JsonArrayConverter());
        converterRegistry.putCustom(JSONObject.class,new JsonConverter());
        converterRegistry.putCustom(String[].class,new StringArrayConverter());
    }

    public static <T> void addCustomConverter(Class<T> type,Converter<T> converter){
        converterRegistry.putCustom(type,converter);
    }

    public static <T>T convert(Class<T> type,Object source){
        return converterRegistry.convert(type,source);
    }




}
